from flask import Flask, render_template, jsonify
import random

app = Flask(__name__)

# 扩展特征定义
features = {
    'head': {
        'face_colors': ['#FFB6C1', '#FFE4C4', '#F0E68C', '#98FB98', '#DEB887'],
        'eye_types': ['normal', 'happy', 'sleepy', 'angry', 'cool'],
        'mouth_types': ['smile', 'neutral', 'surprised', 'sad', 'grin'],
        'hair_colors': ['#000000', '#8B4513', '#CD853F', '#4B0082', '#FF69B4'],
        'hair_styles': ['short', 'long', 'spiky', 'curly', 'bald']
    },
    'body': {
        'colors': ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF69B4'],
        'types': ['normal', 'muscular', 'slim', 'tall', 'short'],
        'poses': ['standing', 'ready', 'relaxed', 'battle']
    },
    'clothes': {
        'types': ['shirt', 'jacket', 'robe', 'armor', 'cape'],
        'colors': ['#800080', '#008080', '#000080', '#808000', '#4B0082'],
        'patterns': ['plain', 'striped', 'dotted', 'checkered'],
        'accessories': ['belt', 'scarf', 'necklace', 'none']
    },
    'weapon': {
        'types': ['sword', 'staff', 'bow', 'axe', 'spear', 'shield'],
        'colors': ['#C0C0C0', '#FFD700', '#8B4513', '#4682B4', '#2F4F4F'],
        'effects': ['normal', 'flame', 'ice', 'lightning', 'poison'],
        'sizes': ['small', 'medium', 'large']
    }
}

@app.route('/')
def home():
    return render_template('index.html', features=features)

@app.route('/generate/<category>')
def generate_part(category):
    if category == 'head':
        return jsonify({
            'face_color': random.choice(features['head']['face_colors']),
            'eye_type': random.choice(features['head']['eye_types']),
            'mouth_type': random.choice(features['head']['mouth_types']),
            'hair_color': random.choice(features['head']['hair_colors']),
            'hair_style': random.choice(features['head']['hair_styles'])
        })
    elif category == 'body':
        return jsonify({
            'color': random.choice(features['body']['colors']),
            'type': random.choice(features['body']['types']),
            'pose': random.choice(features['body']['poses'])
        })
    elif category == 'clothes':
        return jsonify({
            'type': random.choice(features['clothes']['types']),
            'color': random.choice(features['clothes']['colors']),
            'pattern': random.choice(features['clothes']['patterns']),
            'accessory': random.choice(features['clothes']['accessories'])
        })
    elif category == 'weapon':
        return jsonify({
            'type': random.choice(features['weapon']['types']),
            'color': random.choice(features['weapon']['colors']),
            'effect': random.choice(features['weapon']['effects']),
            'size': random.choice(features['weapon']['sizes'])
        })

@app.route('/save', methods=['POST'])
def save_character():
    # 这里可以添加保存角色配置的功能
    return jsonify({'status': 'success'})

if __name__ == '__main__':
    app.run(debug=True) 